<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="renderer" content="webkit" />
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>2元红包轻松撸</title>
    <script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
    <script src="https://cdn.bootcss.com/html2canvas/0.5.0-beta4/html2canvas.min.js"></script>
    <!-- <script src="html2canvas.min.js"></script> -->
    <style>
        article, aside, audio, blockquote, body, canvas, dd, details, div, dl,
        dt, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6,
        header, hgroup, input, li, mark, menu, nav, ol, p, pre, section,
        summary, table, tbody, td, textarea, tfoot, th, thead, time, ul, video
        { margin: 0; padding: 0; }
        article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block }
        table { border-spacing: 0; border-collapse: collapse }
        fieldset, img { border: 0; vertical-align: top }
        address, caption, cite, code, dfn, em, strong, th, var { font-weight: 400; font-style: normal }
        ol, ul { list-style: none }
        h1, h2, h3, h4, h5, h6 { font-weight: 400; font-size: 100% }
        abbr, acronym { border: 0 }
        a { color: #595959; text-decoration: none; cursor: pointer }
        textarea { resize: vertical; overflow-y: auto; outline: 0 none; }
        body { font: 12px/1.5 'Microsoft YaHei', sans-serif }
        html { height: 100% }
        @media screen and (min-width:320px) { html { font-size: 32px } }
        @media screen and (min-width:340px) { html { font-size: 34px } }
        @media screen and (min-width:360px) { html { font-size: 36px } }
        @media screen and (min-width:380px) { html { font-size: 38px } }
        @media screen and (min-width:400px) { html { font-size: 40px } }
        @media screen and (min-width:420px) { html { font-size: 42px } }
        @media screen and (min-width:440px) { html { font-size: 44px } }
        @media screen and (min-width:460px) { html { font-size: 46px } }
        @media screen and (min-width:480px) { html { font-size: 48px } }
        @media screen and (min-width:500px) { html { font-size: 50px } }
        @media screen and (min-width:520px) { html { font-size: 52px } }
        @media screen and (min-width:540px) { html { font-size: 54px } }
        @media screen and (min-width:560px) { html { font-size: 56px } }
        @media screen and (min-width:580px) { html { font-size: 58px } }
        @media screen and (min-width:600px) { html { font-size: 60px } }
        @media screen and (min-width:620px) { html { font-size: 62px } }
        @media screen and (min-width:640px) { html { font-size: 64px } }
        html { height: 100% }
        html body { margin: 0 auto; -webkit-box-sizing: border-box; }
        .wp { overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
        .hide { display: none !important }
        .clearfix:after, .clearfix:before { content: ""; display: table }
        .clearfix:after { clear: both }
        .clearfix { zoom: 1 }
        a,button { -webkit-tap-highlight-color: rgba(0,0,0,0); -webkit-appearance:none; outline:none;}
        .bg {
            display: block;
            width: 100%;
        }
        .box {
            box-sizing: border-box;
            background: #e75143;
            padding: 0.8rem 0.293rem 0.933rem;
        }
        .info {
            background: #fff;
            border-radius: 0.4rem;
            box-sizing: border-box;
            padding: 0.3rem 0.8rem;
            display: flex;
        }
        .info h4 {
            font-size: .4rem;
            color: #cc372f;
            font-weight: bold;
            line-height: 1.12rem;
        }
        .info p {
            font-size: 0.347rem;
            line-height: 0.507rem;
            color: #333333;
        }
        .code {
            width: 90px;
            height: 90px;
            margin-right: 0.533rem;
        }
        .code img {
            display: block;
            width: 100%;
        }
    </style>
</head>
<body>
<div style="display:none;"><img style="position: absolute; visibility: hidden;" id="shareTitleImg" src="http://yy.82ft.cn/o_u/titleBG.jpg"></div>
<img id="canvasImg" style="width: 100%;"/>
<div id="capture" style="position:relative;">
    <div><img src="bg.jpg" class="bg"></div>
    <div class="box">
        <div class="info">
            <div id="code" class="code"></div> 
            <!-- <div id="codeImg" class="code"></div>  -->
            <div>
                <h4>我的专属邀请码：<span id="inviteCode"></span></h4>
                <p>新用户扫一扫我的专属二维码<br>将自动绑定成为我的下级</p>
            </div>
        </div>
    </div>
</div>
<div id="canvasBox" class="hide">
    <canvas id="canvas"></</canvas>
</div>
</body>
<script>

window.onload = function () {

    const url = new URL(location.href)
    const state = url.searchParams.get('state') // 邀请码
    let imgBlob = ''
    var canvas = document.getElementById('canvas')
    var context = canvas.getContext("2d");
	var scale = 2;

    $('#inviteCode').html(state)
    $('#code').qrcode({
        ecLevel: 'L',
        width: 90,
        height:90,
        text: url.origin + '/qicks/promo/red?state='+state
    })

    const w = $('#capture').outerWidth()
    const h = $('#capture').height()
    canvas.width = w * scale
	canvas.height = h * scale

    canvas.getContext("2d").scale(scale, scale)

    html2canvas(document.getElementById("capture"), {
        canvas: canvas,
        scale: scale,
        allowTaint: false, //允许污染
        taintTest: true, //在渲染前测试图片(没整明白有啥用)
        useCORS: true, //使用跨域(当allowTaint为true时这段代码没什么用)
        background: "#e96558", // canvas的背景色
        dpi: window.devicePixelRatio,// window.devicePixelRatio是设备像素比
        logging: true,
        onrendered: function (canvas) {
            $('#capture').hide()
            imgBlob = canvas.toDataURL('image/jpeg', 1.0) //将图片转为base64
            // imgBlob = imgBlob.toString().substring(imgBlob.indexOf(",") + 1)//截取base64以便上传
            $('#canvasImg').attr('src', imgBlob)
        }
    })
}
</script>
</html>